<template>
    <div class="container">

        <div class="body_wrap">
            <el-card class="body_card" shadow="hover" ref="content_card">
                <div class="header_back_wrap">
                    <el-page-header @back="$router.back(-1)" :content="$route.meta.title" class="headerBack"></el-page-header>
                    <el-divider></el-divider>
                </div>

                <div class="form_content">
                    <div class="table_form_wrap">
                        <el-form ref="form" :model="form" :rules="rules" @keyup.enter.native="handleSubmit()" label-width="120px">
                            <el-form-item label="会员ID" prop="memberId">
                                <el-input placeholder="" v-model="form.memberId" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="用户名" prop="memberUsername">
                                <el-input placeholder="" v-model="form.memberUsername" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="使用的优惠券" prop="couponId">
                                <el-input placeholder="" v-model="form.couponId" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="订单总额" prop="totalAmount">
                                <el-input placeholder="" v-model="form.totalAmount" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="应付总额" prop="payAmount">
                                <el-input placeholder="" v-model="form.payAmount" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="运费金额" prop="freightAmount">
                                <el-input placeholder="" v-model="form.freightAmount" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="促销优惠金额（促销价、满减、阶梯价）" prop="promotionAmount">
                                <el-input placeholder="" v-model="form.promotionAmount" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="积分抵扣金额" prop="integrationAmount">
                                <el-input placeholder="" v-model="form.integrationAmount" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="优惠券抵扣金额" prop="couponAmount">
                                <el-input placeholder="" v-model="form.couponAmount" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="后台调整订单使用的折扣金额" prop="discountAmount">
                                <el-input placeholder="" v-model="form.discountAmount" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="订单类型：0->实物订单，2->非实物订单（非实物订单不享受任何折扣），3->活动订单" prop="orderType">
                                <el-input placeholder="" v-model="form.orderType" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="支付方式：1->支付宝；2->微信；3->银联； 4->货到付款" prop="payType">
                                <el-input placeholder="" v-model="form.payType" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="订单来源：0->PC订单；1->微信订单，2->APP订单" prop="sourceType">
                                <el-input placeholder="" v-model="form.sourceType" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="订单状态：0->待付款；1->待发货；2->已发货；3->已完成；4->已关闭；" prop="status">
                                <el-input placeholder="" v-model="form.status" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="是否支付：0->未支付，1->已支付" prop="isPay">
                                <el-input placeholder="" v-model="form.isPay" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="申请退款：0->否，1->是" prop="isRefund">
                                <el-input placeholder="" v-model="form.isRefund" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="收货方式：0->送货上门，2->自提" prop="deliverType">
                                <el-input placeholder="" v-model="form.deliverType" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="物流公司" prop="deliveryCompany">
                                <el-input placeholder="" v-model="form.deliveryCompany" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="物流单号" prop="deliverySn">
                                <el-input placeholder="" v-model="form.deliverySn" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="自动确认时间（天）" prop="autoConfirmDay">
                                <el-input placeholder="" v-model="form.autoConfirmDay" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="可以获得的积分" prop="integration">
                                <el-input placeholder="" v-model="form.integration" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="可以获得的成长值" prop="growth">
                                <el-input placeholder="" v-model="form.growth" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="发票类型：0->不开发票；1->电子发票；2->纸质发票" prop="billType">
                                <el-input placeholder="" v-model="form.billType" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="发票抬头" prop="billHeader">
                                <el-input placeholder="" v-model="form.billHeader" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="发票内容" prop="billContent">
                                <el-input placeholder="" v-model="form.billContent" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="收票人电话" prop="billReceiverPhone">
                                <el-input placeholder="" v-model="form.billReceiverPhone" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="收票人邮箱" prop="billReceiverEmail">
                                <el-input placeholder="" v-model="form.billReceiverEmail" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="收货人姓名" prop="receiverName">
                                <el-input placeholder="" v-model="form.receiverName" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="收货人电话" prop="receiverPhone">
                                <el-input placeholder="" v-model="form.receiverPhone" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="收货人邮编" prop="receiverPostCode">
                                <el-input placeholder="" v-model="form.receiverPostCode" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="省份/直辖市" prop="receiverProvince">
                                <el-input placeholder="" v-model="form.receiverProvince" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="城市" prop="receiverCity">
                                <el-input placeholder="" v-model="form.receiverCity" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="区" prop="receiverRegion">
                                <el-input placeholder="" v-model="form.receiverRegion" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="详细地址" prop="receiverDetailAddress">
                                <el-input placeholder="" v-model="form.receiverDetailAddress" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="订单备注" prop="note">
                                <el-input placeholder="" v-model="form.note" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="下单时使用的积分" prop="useIntegration">
                                <el-input placeholder="" v-model="form.useIntegration" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="支付完成时间" prop="paymentTime">
                                <el-input placeholder="" v-model="form.paymentTime" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="微信支付成功返回的订单号" prop="transactionId">
                                <el-input placeholder="" v-model="form.transactionId" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="发货时间" prop="deliveryTime">
                                <el-input placeholder="" v-model="form.deliveryTime" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="确认收货时间" prop="receiveTime">
                                <el-input placeholder="" v-model="form.receiveTime" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="评价时间" prop="commentTime">
                                <el-input placeholder="" v-model="form.commentTime" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="订单附加信息" prop="extraJson">
                                <el-input placeholder="" v-model="form.extraJson" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="确认收货状态[0->未确认；1->已确认]" prop="confirmStatus">
                                <el-input placeholder="" v-model="form.confirmStatus" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="删除状态【0->未删除；1->已删除】" prop="deleteStatus">
                                <el-input placeholder="" v-model="form.deleteStatus" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="创建时间" prop="ctime">
                                <el-input placeholder="" v-model="form.ctime" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <el-form-item label="最后更新时间" prop="utime">
                                <el-input placeholder="" v-model="form.utime" clearable style="width: 30%"></el-input>
                            </el-form-item>
                            <!--
                            <el-form-item label="状态" prop="status">
                                <el-radio-group v-model="form.status">
                                    <el-radio-button :label="1">正常</el-radio-button>
                                    <el-radio-button :label="0">锁定</el-radio-button>
                                </el-radio-group>
                            </el-form-item>
                            <el-form-item label="性别" prop="sex">
                                <el-select v-model="form.sex" placeholder="请选择">
                                    <el-option label="男" value="男"></el-option>
                                    <el-option label="女" value="女"></el-option>
                                </el-select>
                            </el-form-item>
                            <el-form-item label="生日" prop="birthday">
                                <el-date-picker
                                    v-model="form.birthday"
                                    type="date"
                                    placeholder="选择日期"
                                    value-format="yyyy-MM-dd"
                                    style="width: 63%;">
                                </el-date-picker>
                            </el-form-item>
                            <el-form-item label="备注" prop="remarks">
                                <el-input v-model="form.remarks" type="textarea" :rows="4" placeholder="请输入内容" style="width: 80%;"></el-input>
                            </el-form-item>
                            -->

                        </el-form>
                    </div>
                </div>

                <div class="foot_submit">
                    <el-button @click="$router.back(-1)">返 回</el-button>
                    <el-button @click="handleSubmit" type="primary" :loading="submitLoading">提 交</el-button>
                </div>

            </el-card>
        </div>



    </div>
</template>

<script>
    export default {
        data() {
            return {
                submitLoading: false,
                form: {
                    memberId: null,
                    memberUsername: null,
                    couponId: null,
                    totalAmount: null,
                    payAmount: null,
                    freightAmount: null,
                    promotionAmount: null,
                    integrationAmount: null,
                    couponAmount: null,
                    discountAmount: null,
                    orderType: null,
                    payType: null,
                    sourceType: null,
                    status: null,
                    isPay: null,
                    isRefund: null,
                    deliverType: null,
                    deliveryCompany: null,
                    deliverySn: null,
                    autoConfirmDay: null,
                    integration: null,
                    growth: null,
                    billType: null,
                    billHeader: null,
                    billContent: null,
                    billReceiverPhone: null,
                    billReceiverEmail: null,
                    receiverName: null,
                    receiverPhone: null,
                    receiverPostCode: null,
                    receiverProvince: null,
                    receiverCity: null,
                    receiverRegion: null,
                    receiverDetailAddress: null,
                    note: null,
                    useIntegration: null,
                    paymentTime: null,
                    transactionId: null,
                    deliveryTime: null,
                    receiveTime: null,
                    commentTime: null,
                    extraJson: null,
                    confirmStatus: null,
                    deleteStatus: null,
                    ctime: null,
                    utime: null
                },
                rules: {
                    memberId: [
                        { required: true, message: '会员ID不能为空', trigger: 'blur' }
                    ],
                    memberUsername: [
                        { required: true, message: '用户名不能为空', trigger: 'blur' }
                    ],
                    couponId: [
                        { required: true, message: '使用的优惠券不能为空', trigger: 'blur' }
                    ],
                    totalAmount: [
                        { required: true, message: '订单总额不能为空', trigger: 'blur' }
                    ],
                    payAmount: [
                        { required: true, message: '应付总额不能为空', trigger: 'blur' }
                    ],
                    freightAmount: [
                        { required: true, message: '运费金额不能为空', trigger: 'blur' }
                    ],
                    promotionAmount: [
                        { required: true, message: '促销优惠金额（促销价、满减、阶梯价）不能为空', trigger: 'blur' }
                    ],
                    integrationAmount: [
                        { required: true, message: '积分抵扣金额不能为空', trigger: 'blur' }
                    ],
                    couponAmount: [
                        { required: true, message: '优惠券抵扣金额不能为空', trigger: 'blur' }
                    ],
                    discountAmount: [
                        { required: true, message: '后台调整订单使用的折扣金额不能为空', trigger: 'blur' }
                    ],
                    orderType: [
                        { required: true, message: '订单类型：0->实物订单，2->非实物订单（非实物订单不享受任何折扣），3->活动订单不能为空', trigger: 'blur' }
                    ],
                    payType: [
                        { required: true, message: '支付方式：1->支付宝；2->微信；3->银联； 4->货到付款不能为空', trigger: 'blur' }
                    ],
                    sourceType: [
                        { required: true, message: '订单来源：0->PC订单；1->微信订单，2->APP订单不能为空', trigger: 'blur' }
                    ],
                    status: [
                        { required: true, message: '订单状态：0->待付款；1->待发货；2->已发货；3->已完成；4->已关闭；不能为空', trigger: 'blur' }
                    ],
                    isPay: [
                        { required: true, message: '是否支付：0->未支付，1->已支付不能为空', trigger: 'blur' }
                    ],
                    isRefund: [
                        { required: true, message: '申请退款：0->否，1->是不能为空', trigger: 'blur' }
                    ],
                    deliverType: [
                        { required: true, message: '收货方式：0->送货上门，2->自提不能为空', trigger: 'blur' }
                    ],
                    deliveryCompany: [
                        { required: true, message: '物流公司不能为空', trigger: 'blur' }
                    ],
                    deliverySn: [
                        { required: true, message: '物流单号不能为空', trigger: 'blur' }
                    ],
                    autoConfirmDay: [
                        { required: true, message: '自动确认时间（天）不能为空', trigger: 'blur' }
                    ],
                    integration: [
                        { required: true, message: '可以获得的积分不能为空', trigger: 'blur' }
                    ],
                    growth: [
                        { required: true, message: '可以获得的成长值不能为空', trigger: 'blur' }
                    ],
                    billType: [
                        { required: true, message: '发票类型：0->不开发票；1->电子发票；2->纸质发票不能为空', trigger: 'blur' }
                    ],
                    billHeader: [
                        { required: true, message: '发票抬头不能为空', trigger: 'blur' }
                    ],
                    billContent: [
                        { required: true, message: '发票内容不能为空', trigger: 'blur' }
                    ],
                    billReceiverPhone: [
                        { required: true, message: '收票人电话不能为空', trigger: 'blur' }
                    ],
                    billReceiverEmail: [
                        { required: true, message: '收票人邮箱不能为空', trigger: 'blur' }
                    ],
                    receiverName: [
                        { required: true, message: '收货人姓名不能为空', trigger: 'blur' }
                    ],
                    receiverPhone: [
                        { required: true, message: '收货人电话不能为空', trigger: 'blur' }
                    ],
                    receiverPostCode: [
                        { required: true, message: '收货人邮编不能为空', trigger: 'blur' }
                    ],
                    receiverProvince: [
                        { required: true, message: '省份/直辖市不能为空', trigger: 'blur' }
                    ],
                    receiverCity: [
                        { required: true, message: '城市不能为空', trigger: 'blur' }
                    ],
                    receiverRegion: [
                        { required: true, message: '区不能为空', trigger: 'blur' }
                    ],
                    receiverDetailAddress: [
                        { required: true, message: '详细地址不能为空', trigger: 'blur' }
                    ],
                    note: [
                        { required: true, message: '订单备注不能为空', trigger: 'blur' }
                    ],
                    useIntegration: [
                        { required: true, message: '下单时使用的积分不能为空', trigger: 'blur' }
                    ],
                    paymentTime: [
                        { required: true, message: '支付完成时间不能为空', trigger: 'blur' }
                    ],
                    transactionId: [
                        { required: true, message: '微信支付成功返回的订单号不能为空', trigger: 'blur' }
                    ],
                    deliveryTime: [
                        { required: true, message: '发货时间不能为空', trigger: 'blur' }
                    ],
                    receiveTime: [
                        { required: true, message: '确认收货时间不能为空', trigger: 'blur' }
                    ],
                    commentTime: [
                        { required: true, message: '评价时间不能为空', trigger: 'blur' }
                    ],
                    extraJson: [
                        { required: true, message: '订单附加信息不能为空', trigger: 'blur' }
                    ],
                    confirmStatus: [
                        { required: true, message: '确认收货状态[0->未确认；1->已确认]不能为空', trigger: 'blur' }
                    ],
                    deleteStatus: [
                        { required: true, message: '删除状态【0->未删除；1->已删除】不能为空', trigger: 'blur' }
                    ],
                    ctime: [
                        { required: true, message: '创建时间不能为空', trigger: 'blur' }
                    ],
                    utime: [
                        { required: true, message: '最后更新时间不能为空', trigger: 'blur' }
                    ],
                }
            }
        },

        created() {
            this.form.id = this.$route.query.id
        },

        mounted() {
            this.$nextTick(() => {
                if(this.form.id) {
                    this.getInfo(this.form.id)
                }
            })
        },

        methods: {

            /**
             * 详细信息
             */
            async getInfo(id) {
                if (id) {
                    const res = await this.$http({
                        url: '/mall/omsorder/info/' + id,
                        method: 'GET'
                    })
                    this.form = Object.assign({}, res.data)
                }
            },


            /**
             * 提交表单
             */
            async handleSubmit() {
                const refs = this.$refs
                this.submitLoading = true
                const valid = await refs['form'].validate().catch(() => {})
                if(valid) {
                    const res = await this.$http({
                        url: `/mall/omsorder/${!this.form.id ? 'save' : 'update'}`,
                        method: 'POST',
                        data: this.form
                    })
                    if (this.ResultMessage(res)) {
                        this.$router.back(-1)
                        refs['form'].resetFields()

                        this.submitLoading = false
                    } else {
                        this.submitLoading = false
                    }
                } else {
                    this.submitLoading = false
                }
            }
        }
    }
</script>

<style lang="scss" scoped>



</style>
